Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu item API #79

Merged
merged 12 commits into from
Jan 12, 2024
Merged

Menu item API #79

merged 12 commits into from
Jan 12, 2024

Conversation

tehsmeely
Copy link
Contributor

Exposes an api in System for adding (etc) menu items.

Slightly painful since it involves passing callbacks into C but it's handled by double-boxing dynamic Fn() trait objects.

There's some degree of code around handling the possible kinds of MenuItem values (as MenuItemKind).
Potentially one could go a step further so users do not have the directly deal with the index value and can get
its typed (bool or string) accordingly.

Adds a new example that adds one of each menu item

src/system.rs Outdated Show resolved Hide resolved
@boozook
Copy link
Member

boozook commented Jan 4, 2024

@tehsmeely, thank you for your attempt to make the better implementation! 👍

Just one question. Have you seen another attempt? Could you please compare yours with that?

One of the advantages that I see here is that there are no generics, which makes it easier to use. However, the UserData type is lost here, which is a disadvantage.

@tehsmeely
Copy link
Contributor Author

@tehsmeely, thank you for your attempt to make the better implementation! 👍

Just one question. Have you seen another attempt? Could you please compare yours with that?

One of the advantages that I see here is that there are no generics, which makes it easier to use. However, the UserData type is lost here, which is a disadvantage.

As far as I'm aware there's little to no need for userdata handling here as that's primarily the C handling for generic callback functions. Since we're using rust closures in this implementation, we can include any relevant userdata into that thunk and continue from there.

@tehsmeely
Copy link
Contributor Author

I just pushed a fix for a soundness issue where one could drop a MenuItem and result in the item still being visible in the menu, at which point pressing would result in reading of unmanaged memory.

Worked around this by forcing the "removeMenuItem" call in the drop impl for MenuItem instead. The remove_menu_item method still exists but it's just an explicit drop.

removeAllMenuItems is gone because it doesn't make sense as it would leave MenuItems with dangling pointers. This is not a problem from the API since it's easier to just drop MenuItems

@boozook boozook merged commit 26afcc3 into pd-rs:main Jan 12, 2024
1 check passed
@boozook boozook linked an issue Jan 17, 2024 that may be closed by this pull request
@tehsmeely tehsmeely deleted the menu_item_api branch January 21, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to system menu API
2 participants